package com.it2297.renderer;

import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;


import com.it2297.model.Workshop;

public class WorkshopCellRenderer extends JLabel implements TableCellRenderer  {

	private  Workshop workshop=new Workshop();
	
	public WorkshopCellRenderer()
	{
		setOpaque(true);
		setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 12));
		setVerticalTextPosition(JLabel.TOP);
		setIconTextGap(10);
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object object, boolean isSelected, boolean hasFocus, int row, int column) {
		workshop = (Workshop) object;
		
		switch(column){
		case 0:
			Image bg = Toolkit.getDefaultToolkit().createImage(System.getProperty("user.dir") + "/img/Workshopimg/" + workshop.getWorkshopId() + ".jpg").getScaledInstance(120,  80, Image.SCALE_DEFAULT);
			setIcon(new ImageIcon(bg));
			setText("<html><strong> Workshop Name:</strong> " + workshop.getTitle()+ "<strong><br/> Location:</strong> "+ workshop.getLocation() +"<br/><strong>Date Start:</strong> " +workshop.getDateStart()+ "<strong><br/>Date End:</strong> "+workshop.getDateEnd()+ "</html>");
			break;
		case 1:
			setIcon(null);
			setText("<html><strong><br/>Description:</strong> "+ workshop.getDescription()+ "<br/><strong> Available Slot: </strong> "+ workshop.getAvailableSlot()+  "<br/><strong> Capacity:</strong> "+ workshop.getCapacity()+"<strong><br/>Trainer NRIC:</strong> "+ workshop.getNric()+ "</html>");
			break;
				
		}
		
		if(row % 5 ==0){
			setBackground(Color.LIGHT_GRAY);
		}else{
			setBackground(Color.WHITE);
		}
		
		setForeground(Color.BLACK);
		
		if(isSelected){
			setForeground(new Color(255,255,255));
			setBackground(new Color(80,80,80));
		}
		
		return this;
	}

}